|
|
|
|
|
|
|
In the Employees class, youll find a Collection class declared in the General Declarations area of the class module: |
|
|
|
 |
|
|
|
|
Private mcolEmps As Collection |
|
|
|
|
|
|
|
|
Of course, youll need to create a new instance of this Collection class. This you can do in the Class_Initialize() event, like this: |
|
|
|
 |
|
|
|
|
Private Sub Class_Initialize()
Set mcolEmps = New Collection
End Sub |
|
|
|
|
|
|
|
|
Youll find an Add method in this class, but it does not accept objects. Instead, it only accepts EmployeeID, FirstName, LastName, and Salary values. This forces you to pass in employee data only, not just any data type you want: |
|
|
|
 |
|
|
|
|
Public Function Add(ByVal EmpID As Long, _
ByVal FirstName As String, _
ByVal LastName As String, _
ByVal Salary As Currency) As Employee
Dim oEmp As Employee
Set oEmp = New Employee
' Load Properties of New Class
With oEmp
.EmpID = EmpID
.FirstName = FirstName
.LastName = LastName
.Salary = Salary
End With
' Add To Private Collection
mcolEmps.Add oEmp, CStr(EmpID)
Set Add = oEmp
End Function |
|
|
|
|
|
|
|
|
In the Add method, you create a new Employee object, fill in the properties from the arguments passed to this method, and then add the Employee object to the private collection in this class. Its customary to return the newly created Employee object from the Add method, so thats what you should do in your Add method as well. |
|
|
|
|
|